﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using simpleHotel.Business;

namespace simpleHotel.Web.UserControls
{
    public partial class ucFindHotelQuick : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GetProvinces();
            }
        }


        private void GetProvinces()
        {
            HotelBLL obj = new HotelBLL();
            DataTable tb = new DataTable();
            tb = obj.GetProvinces();
            if (tb != null)
            {
                ddlProvince.DataSource = tb;
                ddlProvince.DataTextField = "Description";
                ddlProvince.DataValueField = "ID";
                ddlProvince.DataBind();
            }
        }

        protected void ctrlButtonSearch_Click(object sender, EventArgs e)
        {
            string param = "HotelList.aspx?";

            if (txtHotelName.Text != null)
            {
                param += "hn=" + txtHotelName.Text + "&";
            }

            if (ddlProvince.SelectedValue != null)
            {
                param += "prv=" + ddlProvince.SelectedValue;
                Session.Add("LOCATION", ddlProvince.SelectedItem);
                Session.Add("LOCATIONID", ddlProvince.SelectedValue);
            }

            if (!string.IsNullOrEmpty(fromdate.Text) && !string.IsNullOrEmpty(todate.Text))
            {
                Session.Add("CHECKINDATE", fromdate.Text.Trim());
                Session.Add("CHECKOUTDATE", todate.Text.Trim());
            }
            else
            {
                Session.Remove("CHECKINDATE");
                Session.Remove("CHECKOUTDATE");
                Session.Abandon();
            }

            //may contains 'star-1','star-2','star-3','star-4','star-5'
            Session["STANDARD"] = hfStandard.Value;

            Response.Redirect(param);
        }

        //protected void ddlStar_OnselectedIndexChanged(object sender, EventArgs e)
        //{
        //    BindTitles();
        //}

        //protected void BindTitles()
        //{
        //    if (ddlStar != null)
        //    {
        //        foreach (ListItem li in ddlStar.Items)
        //        {
        //            li.Attributes["title"] = "Images/" + li.Value; 
        //        }
        //    }
        //}
    }
}